package com.numberma.userservice.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.numberma.userservice.Result.PageResult;
import com.numberma.userservice.Result.Result;

import com.numberma.userservice.entity.Dto.UserDto;
import com.numberma.userservice.entity.Dto.UserIdPasswordDto;
import com.numberma.userservice.entity.Dto.UserLoginDto;
import com.numberma.userservice.entity.Dto.UserPageDto;
import com.numberma.userservice.entity.Users;
import com.numberma.userservice.entity.VO.UserVo;
import com.numberma.userservice.service.IUserService;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private IUserService userService;

    @PostMapping("/user/register")
    public Result register(@RequestBody Users user) throws JsonProcessingException {
         return  userService.register(user);



    }

    @PostMapping("/user/login")
    public Result login(@RequestBody UserLoginDto userLoginDto) {
          return userService.login(userLoginDto);


    }
    @GetMapping("/users")
    public PageResult getPageUsers(@RequestBody UserPageDto userPageDto) {
          return userService.getPageUsers(userPageDto);


    }
    @GetMapping("/user/{userId}")
    public Result getUser(@PathVariable Long userId) {
         return  userService.GetUser(userId);


    }
    @PutMapping("/user/{userId}")
    public Result updateUser(@PathVariable("userId") Long userId,@RequestBody UserDto userDto) {

        return userService.updateUser(userId,userDto);


    }
    @PostMapping("/user/reset-password")
    public Result resetPassword(@RequestBody UserIdPasswordDto userIdPasswordDto) {
          return userService.resetPassword(userIdPasswordDto);


    }




}
